package lab03.test07;

import java.io.*;
import java.util.Enumeration;
import java.util.zip.ZipEntry;
import java.util.zip.ZipFile;

public class Test {
    public static void main(String[] args) {
        String path = "d:\\test.zip";

        ZipFile zipFile = null;
        ZipEntry zipEntry = null;
        InputStream fileInputStream = null;
        FileOutputStream fileOutputStream = null;
        try {
            zipFile = new ZipFile(path);
            zipFile.entries();
            //枚举
            Enumeration enteries = zipFile.entries();


            while (enteries.hasMoreElements()) {
                zipEntry = (ZipEntry) enteries.nextElement();
                System.out.println(zipEntry);

                File file = new File("d:\\test");
                file.mkdir();

               fileInputStream = zipFile.getInputStream(zipEntry);
                fileOutputStream = new FileOutputStream(new File("d:\\test\\" + zipEntry.getName()));

                byte[] data = new byte[1024];
                while((fileInputStream.read(data)) != -1){
                    fileOutputStream.write(data);
                }
            }
        } catch (IOException e) {
            e.printStackTrace();
        } finally {
            try {
                zipFile.close();
                fileInputStream.close();
                fileOutputStream.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    }
}
